﻿/*
    a07_Yield @ https://gitee.com/zcatt/MyDemo2020
yield return语句用于实现IEnumerable或IEnumerable<T>.
yield break语句用于强制结束, 此例没有展示.

 */

using System;
using System.Collections;
using System.Collections.Generic;

class MyArray
{
    public ArrayList m_list;

    public MyArray()
    {
        m_list = new ArrayList();
    }

    public MyArray Add(int a)
    {
        m_list.Add(a);
        return this;
    }

    public IEnumerable<int> GetElement()
    {
        foreach (int e in m_list)
            yield return e;
    }
}

class Program
{
    static void Main(string[] args)
    {
        MyArray a = new MyArray();
        a.Add(1).Add(2).Add(3).Add(4);
        foreach (int i in a.GetElement())
            Console.WriteLine(i);

        return;       
    }
}


